package com.codegen.enums;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
import lombok.Getter;
import org.apache.commons.lang3.ArrayUtils;

/**
 * 表字段关系
 *
 * @author LZCXTECH06
 * @date 2019年9月9日
 */
@JsonFormat(shape = Shape.OBJECT)
@Getter
public enum RelationType {
    /**
     * 单表/主表
     */
    SINGLE("单表", false, ArrayUtils.toArray(ListLayout.LIST), ArrayUtils.toArray(DefaultField.ID, DefaultField.CREATE_BY, DefaultField.CREATE_TIME, DefaultField.UPDATE_BY, DefaultField.UPDATE_TIME, DefaultField.REMARKS, DefaultField.DEL_FLAG)),

    /**
     * 主表
     */
    //MAIN("主表", true, ArrayUtils.toArray(ListLayout.LIST), FormLayout.values()),
    /**
     * 自关联（树结构）
     */
    TREE("树结构表", true, ArrayUtils.toArray(ListLayout.TABLE_TREE), DefaultField.values()),
    /**
     * 一对一（扩展表）
     */
    EXTENSION("扩展表", true, ArrayUtils.toArray(ListLayout.LIST), ArrayUtils.toArray(DefaultField.ID, DefaultField.CREATE_BY, DefaultField.CREATE_TIME, DefaultField.UPDATE_BY, DefaultField.UPDATE_TIME, DefaultField.REMARKS, DefaultField.DEL_FLAG)),
    /**
     * 多对一（主子表）
     */
    SUBLIST("子表", true, ArrayUtils.toArray(ListLayout.LIST, ListLayout.LTREE_RLIST), ArrayUtils.toArray(DefaultField.ID, DefaultField.CREATE_BY, DefaultField.CREATE_TIME, DefaultField.UPDATE_BY, DefaultField.UPDATE_TIME, DefaultField.REMARKS, DefaultField.DEL_FLAG));

    RelationType(String desc, boolean needFk, ListLayout[] allowListLayout, DefaultField[] defaultFields) {
        this.desc = desc;
        this.needFk = needFk;
        this.allowListLayout = allowListLayout;
        //this.allowFormLayout = allowFormLayout;
        this.defaultFields = defaultFields;
    }

    private String desc;
    private boolean needFk;
    private ListLayout[] allowListLayout;
    private DefaultField[] defaultFields;
    //private FormLayout[] allowFormLayout;

    public String getName() {
        return name();
    }
}
